package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分类管理
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 新增管理分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        return categoryService.addCategory(categoryDTO);
    }

    /**
     * 分页查询菜品信息
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageCategory(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("菜品分类：{}" + categoryPageQueryDTO);
        return categoryService.pageCategory(categoryPageQueryDTO);
    }

    /**
     * 根据ID删除分类
     * @return
     */
    @DeleteMapping
    public Result deleteByCategoryID(Integer id){

        return categoryService.deleteByCategoryID(id);
    }

    /**
     * 修改分类名称
     * @param categoryDTO
     * @return
     */
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        return categoryService.updateCategory(categoryDTO);
    }

    /**
     *  修改状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateCategoryStatus(@PathVariable Integer status, Long id){
        return categoryService.updateCategoryStatus(status, id);
    }

    /**
     * 条件查询
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result getCategoryList(Integer type){
        return categoryService.getCategoryList(type);
    }

}
